<?php
require_once "dao/UsuarioDAO.php";

$dao = new UsuarioDAO();

$firstname = mysql_real_escape_string($_POST["firstname"]);
$lastname = mysql_real_escape_string($_POST["lastname"]);

$username = mysql_real_escape_string($_POST["username"]);
$senha = mysql_real_escape_string($_POST["senha"]);

$usuarioExistente = $dao->verificarSeUsuarioExiste($username);

if(!$usuarioExistente){
    $result = $dao->criarUsuario($username, $senha, $firstname, $lastname);
    $userBd = $dao->obterUsuarioByLogin($username, $senha);
    $result2 = $dao->criarInboxFolder($userBd["accountid"]);
    $result3 = $dao->criarSentFolder($userBd["accountid"]);
    $result4 = $dao->criarRascunhoFolder($userBd["accountid"]);
    
    if($result){
        header("Location: ../index.php?newsucess=1");
    }else{
        header("Location: ../novoUsuario.php?nosucess=1");
    }
}else{
    header("Location: ../novoUsuario.php?jaexiste=1");
}


?>
